package com.pengtu.gsj.controller.gcjs;

import javax.servlet.http.HttpServletRequest;


import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.pengtu.gsj.controller.base.DefaultBaseController;
import com.pengtu.gsj.dao.base.Page;
import com.pengtu.gsj.dao.base.QueryFilter;
import com.pengtu.gsj.entity.gcjs.XXRoadConstructionA;
import com.pengtu.gsj.interceptor.Token;
import com.pengtu.gsj.service.gcjs.XXRoadConstructionAService;
import com.pengtu.gsj.service.system.SystemManageService;
import com.pengtu.gsj.utils.web.SpringMvcUtils;

@Controller
@RequestMapping("xXRoadCona")
public class XXRoadConstructionAController extends DefaultBaseController {
	
	@Autowired
	private XXRoadConstructionAService xXRoadConstructionAService;
	
	
	@Autowired
	private SystemManageService systemManageService;
	
	/**
	 * 
	 * getXXRoadConstructionAs:
	 * 适用:按属性要求获取码表列表
	 * @param page 对象集
	 * @param request
	 * @return 码表列表页面
	 * @exception 
	 * @since  1.0.0
	 */
	@ResponseBody
	@RequestMapping(value = "list", produces = "application/json; charset=utf-8")
	public Page<XXRoadConstructionA> getXXRoadConstructionAs(Page<XXRoadConstructionA> page,
			HttpServletRequest request) {
		QueryFilter queryFilter = QueryFilter.buildFromHttpRequest(request);
		if (!page.isOrderBySetted()) {
			page.setOrderBy("year");
			page.setOrder(Page.ASC);
		}
		page = xXRoadConstructionAService.findXXRoadConstructionAs(page, queryFilter);
		return page;
	}
	
	/**
	 * 
	 * loadEntity:
	 * 适用: 每个方法执行之前都会执行该方法
	 * @param id  XXRoadConstructionA主键id
	 * @return 返回持久对象XXRoadConstructionA或者新创建对象
	 * @exception 
	 * @since  1.0.0
	 */
	@ModelAttribute
	public XXRoadConstructionA loadEntity(String id){
		XXRoadConstructionA xXRoadConstructionA ;
		if (StringUtils.isNotEmpty(id)) {
			xXRoadConstructionA = xXRoadConstructionAService.getXXRoadConstructionA(id);
		}else {
			xXRoadConstructionA = new XXRoadConstructionA();
		}
		return xXRoadConstructionA;
	}
	
	/**
	 * 
	 * saveXXRoadConstructionA:保存对象
	 * 适用:
	 * @param XXRoadConstructionA 对象
	 * @param request 请求
	 * @param model 传递参数
	 * @return 码表列表页面
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value = "save", method=RequestMethod.POST)
	@ResponseBody
	@Token(remove = true)
	public boolean saveXXRoadConstructionA(@ModelAttribute XXRoadConstructionA xXRoadConstructionA) {
		xXRoadConstructionAService.saveXXRoadConstructionA(xXRoadConstructionA);
		return true;
	}
	
	
	/**
	 * 
	 * deleteXXRoadConstructionA:删除对象
	 * 适用:
	 * @param id
	 * @param attributes
	 * @return 删除是否成功
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value="delete")
	@ResponseBody
	public boolean deleteXXRoadConstructionA(@ModelAttribute XXRoadConstructionA xXRoadConstructionA){
		return xXRoadConstructionAService.deleteXXRoadConstructionA(xXRoadConstructionA);
	}

	
	/**
	 * 
	 * showXXRoadConstructionA:修改对象
	 * 适用:
	 * @param xXRoadConstructionA 对象
	 * @return 对象
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping(value="show")
	@ResponseBody                                                     
	public XXRoadConstructionA showXXRoadConstructionA(@ModelAttribute XXRoadConstructionA xXRoadConstructionA){
		return xXRoadConstructionA;
	}
	
	
	/**
	 * 
	 * showXXRoadConstructionAList:返回列表页面
	 * 适用:
	 * @param page
	 * @param request
	 * @param model
	 * @return 
	 * @exception 
	 * @since  1.0.0
	 */
	@RequestMapping("listInfo")
	@Token(save = true)
	public String showXXRoadConstructionAList(HttpServletRequest request, Model model) {
		
		return "gcjs/xXRoadConaList";
	}

	/**
	 * checkYear:
	 * 适用:验证县乡公路中的年份唯一
	 * @return 
	 * @exception 
	 * @since  1.0.0
	*/
	@ResponseBody
	@RequestMapping(value="checkYear", produces="application/json; charset=utf-8")
	public Boolean checkYear(){
		String year = SpringMvcUtils.getParameter("testYear");
		String id = SpringMvcUtils.getParameter("id");
		return xXRoadConstructionAService.checkYear(year, id);
	}
}
